package com.senyin.service.impl;

import com.senyin.common.BaseResponse;
import com.senyin.common.ErrorCode;
import com.senyin.common.ResultUtils;
import com.senyin.dao.DeptDao;
import com.senyin.entity.Dept;
import com.senyin.service.DeptService;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;
import java.util.List;
import java.util.Objects;

public class DeptServiceImpl implements DeptService {
    private DeptDao deptDao = new DeptDao();

    @Override
    public BaseResponse<List<Dept>> showAll() throws SQLException {
        return deptDao.showAll();
    }

    @Override
    public BaseResponse addDept(Dept dept, HttpServletRequest request) throws SQLException {
        if (Objects.isNull(dept)||Objects.isNull(request)){
            return ResultUtils.error(ErrorCode.NULL_ERROR,"请求为空");
        }
        return deptDao.addDept(dept, request);
    }

    @Override
    public BaseResponse modDept(Dept dept, HttpServletRequest request) throws SQLException {
        if (Objects.isNull(dept)||Objects.isNull(request)){
            return ResultUtils.error(ErrorCode.NULL_ERROR,"请求为空");
        }
        return deptDao.modDept(dept,request);
    }

    @Override
    public BaseResponse delDeptByUUID(String UUID, HttpServletRequest request) throws SQLException {
        if (Objects.isNull(request)){
            return ResultUtils.error(ErrorCode.NULL_ERROR,"请求为空");
        }
        if (StringUtils.isAnyBlank(UUID)){
            return ResultUtils.error(ErrorCode.NULL_ERROR,"请求为空");
        }
        return deptDao.delDeptByUUID(UUID,request);
    }
}




